package net.tv90.bfmccore.command;

import net.tv90.bfmccore.BFMCCore;
import net.tv90.bfmccore.SlainListener;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import static net.tv90.bfmccore.listener.RibbonListener.clearRibbonData;
import static net.tv90.bfmccore.listener.RibbonListener.printRibbonData;

public class RibbonCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        //清除勋带缓存数据
        if (label.equalsIgnoreCase("ribbon")) {
            if (args.length == 0) {
                sender.sendMessage("/ribbon clear 清除勋带缓存数据");
                sender.sendMessage("/ribbon print 输出勋带缓存数据");
                sender.sendMessage("/ribbon find <type> 查询自己的勋带数据");
                sender.sendMessage("/ribbon find <type> <player> 查询某玩家的勋带数据");
            }
            if (args.length == 1 && args[0].equalsIgnoreCase("clear")) {
                clearRibbonData();
                sender.sendMessage("已清除勋带缓存数据");
                BFMCCore.Logger.info("已清除勋带缓存数据");
            }
            if (args.length == 1 && args[0].equalsIgnoreCase("print")) {
                try {
                    printRibbonData();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                clearRibbonData();
            }
            if (args.length == 2 && args[0].equals("find")) {
                String type = args[1];
                Player p = (Player) sender;
                int num = SlainListener.RibbonNumMap.getOrDefault(p.getName() + "_" + type.toUpperCase() + "_Ribbon", 0);
                p.sendMessage("§e[管理员]你的" + type + "勋带数量为" + num);
            }
            if (args.length == 3 && args[0].equals("find")) {
                String type = args[1];
                Player p = Bukkit.getPlayerExact(args[2]);
                Player s = (Player) sender;
                int num = SlainListener.RibbonNumMap.getOrDefault(p.getName() + "_" + type.toUpperCase() + "_Ribbon", 0);
                s.sendMessage("§e[管理员]玩家" + p.getName() + "的" + type + "勋带数量为" + num);
            }
            return true;
        }
        return true;
    }
}


